<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <template slot="footer">
      <a-button type="primary" style="padding-left: 8px; padding-right: 8px" @click="clearModel"> 清除条件 </a-button>
      <a-button style="padding-left: 8px; padding-right: 8px" @click="close"> 关闭</a-button>
      <a-button type="primary" style="padding-left: 8px; padding-right: 8px" @click="handleOk"> 确定</a-button>
    </template>
    <a-spin :spinning="confirmLoading">
      <div style="margin: 0 auto" :class="{ isCheck: isCheck }">
        <a-radio-group v-model="model.timeType" @change="changeTimeType" style="width: 100%">
          <table class="table table-striped table-bordered" align="center" valign="center">
            <tr>
              <td class="column" colspan="1">账套/核算单元</td>
              <td class="value" colspan="3">
                <a-input @click.native="openOrganModel" v-model="model.accName" readOnly placeholder="请选择" />
              </td>
            </tr>
            <tr>
              <td class="column">
                <a-radio value="1">按期间</a-radio>
              </td>
              <td class="value">
                <a-month-picker
                  :disabled="model.timeType != 1"
                  style="width: 100%"
                  format="YYYY-MM"
                  valueFormat="YYYY-MM"
                  placeholder="请选择期间"
                  v-model="model.startTime"
                />
              </td>
              <td class="column" style="text-align: center;">至</td>
              <td class="value">
                <a-month-picker
                  :disabled="model.timeType != 1"
                  style="width: 100%"
                  format="YYYY-MM"
                  valueFormat="YYYY-MM"
                  placeholder="请选择期间"
                  v-model="model.endTime"
                />
              </td>
            </tr>
            <tr>
              <td class="column"><a-radio value="2">按日期</a-radio></td>
              <td class="value">
                <j-date style="width: 100%" :disabled="model.timeType != 2" v-model="model.startTime"></j-date>
              </td>
              <td class="column" style="text-align: center;">至</td>
              <td class="value">
                <j-date style="width: 100%" :disabled="model.timeType != 2" v-model="model.endTime"></j-date>
              </td>
            </tr>
            <tr>
              <td class="column">科目编号</td>
              <td class="value" colspan="3">
                <a-tree-select
                  v-model="model.subjectCode"
                  tree-data-simple-mode
                  show-search
                  style="width: 100%"
                  :dropdown-style="{ maxHeight: '400px', overflow: 'auto' }"
                  placeholder="请选择"
                  treeNodeFilterProp="title"
                  :tree-data="subjectTreeData"
                  :loadData="onLoadData"
                  @select="onSelectSubjectRadio"
                  allow-clear
                />
              </td>
              <!-- <td class="column">科目分类</td>
              <td class="value">
                <j-dict-select-tag style="width: 100%" v-model="model.subjectType" dict-code="zxzy_subject_type" />
              </td> -->
            </tr>
          </table>
        </a-radio-group>
      </div>
    </a-spin>

    <CheckOrganModal ref="departModal" @ok="updateQueryParam"></CheckOrganModal>
  </a-modal>
</template>

<script>
import CheckOrganModal from '../testcomponent/CheckOrganModal'
import AssistTable from '../components/modules/AssistTable'
import { SearchModalMixin } from '../mixins/SearchModalMixin'
import moment from 'moment'
export default {
  name: 'SearchModel',
  mixins: [SearchModalMixin],
  components: {
    CheckOrganModal,
    AssistTable,
  },
  data() {
    return {
      title: '科目明细账查询条件',
      visible: false,
      model: {
        accCode: '',
        timeType: '2',
        accName: '',
        startTime: moment().format('YYYY-MM-01'),
        endTime: moment().format('YYYY-MM-') + moment().daysInMonth(),
      },
      subjectTreeData: [],
      isCheck: false,
      confirmLoading: false,
      url: {
        edit: '/investigateSasac/edit',
        subjectTree: '/sjyzzx/sjZxzyAccountSubject/queryAllSubjectTree',
      },
    }
  },
  created() {
    this.getSubjectTree()
  },
  watch: {},
  methods: {
    edit(params) {
      this.model = Object.assign({},params)
      this.visible = true
    },
    handleOk() {
      let { startTime, endTime } = this.model
      if (this.compareTime(startTime, endTime)) {
        this.$emit('ok', this.model)
        this.visible = false
      }
    },
    openOrganModel() {
      this.$refs.departModal.edit()
    },
    checkedRows(val) {
      console.log(val)
    },
    handleCancel() {
      this.close()
    },
    changeTimeType(e) {
      if (e.target.value == 1) {
        this.model.startTime = moment().format('YYYY-MM')
        this.model.endTime = moment().format('YYYY-MM')
      } else {
        this.model.startTime = moment().format('YYYY-MM-01')
        this.model.endTime = moment().format('YYYY-MM-') + moment().daysInMonth()
      }
    },
  },
}
</script>

<style scoped>
</style>
<style lang="less" scoped>
@import '../../../css/checkAndEditNoBorder.less';
.table-bordered /deep/ .ant-col-sm-16 {
  width: 100%;
}
</style>